package com.qidian.buy.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qidian.buy.goods.entity.ItemSpecification;
import com.qidian.buy.goods.mapper.ItemSpecificationMapper;
import com.qidian.buy.goods.service.IItemSpecificationService;
import com.qidian.buy.util.pojo.QdResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 戴着假发的程序员
 * @since 2024-05-08
 */
@Service
public class ItemSpecificationServiceImpl extends BaseServiceImpl<ItemSpecification>  implements IItemSpecificationService {
    @Autowired
    private ItemSpecificationMapper speMapper;
    @Override
    public QdResult save(ItemSpecification spe) {
        return QdResult.isSuccess(speMapper.insert(spe));
    }

    @Override
    public QdResult<IPage<ItemSpecification>> list(ItemSpecification spe, int page, int limit) {
        IPage<ItemSpecification> iPage = getPage(page,limit);
        QueryWrapper<ItemSpecification> wrapper = new QueryWrapper<>();
        wrapper.like(spe != null && !StringUtils.isBlank(spe.getSpeName()),"spe_name",spe.getSpeName());
        return QdResult.success(speMapper.selectPage(iPage,wrapper));
    }
}
